﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace UnitTestUtilsTests.ViewModelTests
{
    class TestViewModel
    {
        private readonly TaskScheduler _uiScheduler;

        public TestViewModel(TaskScheduler uiUiScheduler)
        {
            this._uiScheduler = uiUiScheduler;
        }

        public Task SomeMethodSpawningWorkAsync()
        {
            var t = new Task(() =>
                                 {
                                     Console.WriteLine("executing task ..");
                                     
                                     // do some work
                                     Thread.SpinWait(1000);

                                     Console.WriteLine("executed task");
                                 });

            // continuation that needs to be executed on UI thread
            var t2 = t.ContinueWith(task =>
                                        {
                                            Console.WriteLine("Continuation executed");
                                        }, this._uiScheduler);
            t.Start();
            return t2;
        }

    }
}
